package com.zzptc.shop.dao;

import com.zzptc.shop.db.IDB;
import com.zzptc.shop.db.MysqlDBImp;
import com.zzptc.shop.vo.Users;
import com.zzptc.shop.vo.VO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

public class UserDaoImp implements IDAO {
    @Override
    public boolean insert(VO vo)  {
        //获取数据库连接
        IDB db=new MysqlDBImp();
        Connection conn= null;
        PreparedStatement ps=null;
        int i=0;
        try {
            conn = db.getConn();
            //用工具操作数据库
            ps= conn.prepareStatement("insert into t_easybuy_user(eu_user_id,eu_user_name,eu_password)values(?,?,?)");
            //给？注入值
            Users users=(Users)vo;
            ps.setString(1,users.getEu_user_id());
            ps.setString(2,users.getEu_user_name());
            ps.setString(3,users.getEu_password());
            //操作数据库
            i=ps.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            //ps释放 关闭连接
            try {
               // ps.close();
                //这里只有一个资源释放  所以后两个参数为null
                db.closeAll(ps,null,null);
                db.closeConn();
            } catch (SQLException e) {
                e.printStackTrace();
            }


        }


        return i>0;
    }

    @Override
    public List getAll() throws SQLException {
        return null;
    }

    @Override
    public boolean deleteByID(VO vo) throws SQLException {
        return false;
    }

    @Override
    public boolean update(VO vo) throws SQLException {
        return false;
    }

    @Override
    public VO getByID(VO vo) throws SQLException {
        return null;
    }
}
